/*************************************************************************
	> File Name: testfopen.c
	> Author: WangYiFei
	> Mail: 824537320@qq.com
	> Created Time: Mon 11 Jan 2021 10:30:21 PM CST
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// int main() {
//     FILE *fp = NULL;
//     fp = fopen("./test.txt", "w+");
//     char buff[512] = "hello";
//     char buff2[512] = {0};
//     // fwrite(buff, 1, sizeof(buff), fp);
//     fread(buff2, 1, sizeof(buff2), fp);
//     printf("fread = %s\n", buff2);
//     fclose(fp);
// 
// 
//     return 0;
// }
int main() {
    FILE *fp = NULL;
    if ((fp = fopen("./test.txt", "w+")) == NULL) {
        perror("fopen");
        exit(1);
    }
    char hello[512] = "hello";
    fwrite(hello, 1, sizeof(hello), fp);
    while (1) {
        char buff[512] = {0};
        size_t nread = fread(buff, 1, sizeof(buff), fp);
        printf("%s", buff);
        if (nread <= 0) {
            break;
        }
    }
    fclose(fp);
    return 0;
}
